package com.yanqu.road.server.cmd.patrons;

import com.yanqu.road.pb.patrons.PatronsProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_PATRONS_EQUIP_VEHICLE, desc = "门客装备座骑")
public class PatronsEquipVehicleCmd extends AbstractCommand {

	private int patronsId;

	private String vehicleUid;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		PatronsProto.PatronsEquipVehicleReqMsg reqMsg = PatronsProto.PatronsEquipVehicleReqMsg.parseFrom(packet.getBytes());
		patronsId = reqMsg.getPatronsId();
		vehicleUid = reqMsg.getVehicleUid();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(PatronsModule.class).equipVehicle(patronsId, vehicleUid);
	}

	@Override
	public void sendData(GamePlayer player) {
		PatronsProto.PatronsEquipVehicleRespMsg.Builder respMsg = PatronsProto.PatronsEquipVehicleRespMsg.newBuilder();
		respMsg.setRet(ret);
		player.sendPacket(Protocol.U_PATRONS_EQUIP_VEHICLE, respMsg);
	}

}
